/**
 * Created by arron_Li on 18/4/11. // 基于axios改造的全局公共异步请求
 */
import axios from 'axios'
let qs = require('qs')
// import baseUrl from '../static/static.js'
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8' // post 请求增加请求头
// axios.defaults.withCredentials = true // 设置带cookie参数
// let commonUrl = baseUrl.baseUrl
// let commonUrl = "http://wap.mhw.com/api"
let commonUrl = "/api"
// let commonUrl = 'http://localhost:8000/api/api';
export default {
	fetchGet(url, params = {}) {
		return new Promise((resolve, reject) => {
			axios.get(commonUrl + url, {
				params
			}).then(res => {
				resolve(res.data)
			}).catch(error => {
				reject(error)
			})
		})
	},
	fetchPost(url, params = {}) {
		return new Promise((resolve, reject) => {
			axios.post(commonUrl + url, qs.stringify(params)).then(res => {
				resolve(res.data)
			}).catch(error => {
				reject(error)
			})
		})
	}
}